package com.sinoglobal.ningxia.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.MessageListVo;

/**
 * 
 * @author yrq
 * @createdate 2014-7-24 下午16:58:40
 * @Description:我的消息 列表适配器
 */
public class MyMessageAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<MessageListVo> list = new ArrayList<MessageListVo>();

	public MyMessageAdapter(Context context) {
		super();
		this.context = context;
	}

	public ArrayList<MessageListVo> getList() {
		return list;
	}

	public void setList(ArrayList<MessageListVo> list) {
		this.list.addAll(list);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vHolder;
		if (convertView == null) {
			vHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.mymessage_item, null);
			vHolder.partOfMessage = (ImageView) convertView.findViewById(R.id.partofmessage);
			vHolder.messageName = (TextView) convertView.findViewById(R.id.messagename);
			vHolder.messageTime = (TextView) convertView.findViewById(R.id.time);
			vHolder.messageContent = (TextView) convertView.findViewById(R.id.message_content);
			convertView.setTag(vHolder);
		}
		vHolder = (ViewHolder) convertView.getTag();
		if (list.get(position).getType().equals("1")) {
			vHolder.partOfMessage.setImageResource(R.drawable.img_message_tuijian);
		}
		if (list.get(position).getType().equals("2")) {
			vHolder.partOfMessage.setImageResource(R.drawable.img_message_huodong);
		}
		vHolder.messageName.setText(list.get(position).getTitle());
		vHolder.messageTime.setText(list.get(position).getCreate_time());
		vHolder.messageContent.setText(list.get(position).getContent());
		return convertView;
	}

	class ViewHolder {
		public ImageView partOfMessage;
		public TextView messageName;
		public TextView messageTime;
		public TextView messageContent;
	}
}
